from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
testCase = "DBshop006_订单管理删除订单"

# 1.点击销售管理订单管理界面。/
firefox = openBrowser(urlAdmin) #打开后台网页
DBshopLoginAdmin(firefox)   #后台登录
DBshopEnterMenu2(firefox,"销售管理","订单管理")

s = firefox.find_element_by_xpath("//p[@style='font-size: 16px; line-height: 30px;']").text
print(s)
l = "订单管理 - \(订单数："
r = "\)"
num = reGetString(s,l,r)
print(num)

# 2.在订单状态点击已取消一栏，点击“搜索”按钮一款，勾选之后，选择删除，点击提交操作。
#下拉框，选择已取消
from selenium.webdriver.support.select import Select
s = Select(firefox.find_element_by_id("order_state"))
s.select_by_visible_text("已取消")
firefox.find_element_by_xpath("(//button[@class='btn btn-small btn-primary'])[1]").click()
#编辑查看
firefox.find_elements_by_link_text("编辑查看")[0].click()
firefox.find_element_by_link_text("删除订单").click()
time.sleep(3)
firefox.switch_to.alert.accept()
time.sleep(3)
# 3.删除成功
s = firefox.find_element_by_xpath("//p[@style='font-size: 16px; line-height: 30px;']").text
print(s)
l = "订单管理 - \(订单数："
r = "\)"
num1 = reGetString(s,l,r)
print(num1)

if int(num)==int(num1)+1:
    writeLog("%s 测试通过" % (testCase))
else:
    writeLog("%s 测试失败" % (testCase))
    getPhoto(firefox)
firefox.quit()